//********************************************************************
//	created:	17:10:2011   0:17
//	filename: 	service.h
//	author:		tiamo
//	purpose:	service
//********************************************************************

#pragma once

//
// service
//
class Service
{
public:
	//
	// constructor
	//
	Service(UniString const& name, mysql::Database& database) : mName(name), mDatabase(database) {}

	//
	// destructor
	//
	virtual ~Service()														{for(auto it = mChildList.begin(); it != mChildList.end(); ++it){delete *it;}}

	//
	// initialize
	//
	virtual void initialize()												{}

	//
	// cleanup
	//
	virtual void cleanup()													{for(auto it = mChildList.begin(); it != mChildList.end(); ++it){(*it)->cleanup();}}

	//
	// start service
	//
	void startChildService(Service* childService)							{mChildList.push_back(childService); childService->initialize();}

	//
	// get name
	//
	UniString const& getName() const										{return mName;}

	//
	// set name
	//
	void setName(UniString const& name)										{mName = name;}

protected:
	//
	// name
	//
	UniString																mName;

	//
	// database
	//
	mysql::Database&														mDatabase;

	//
	// sub service list
	//
	std::vector<Service*>													mChildList;
};
